<?php

namespace app\admin\model;

use think\Model;
use app\admin\model\Country as CountryModel;


class Ab extends Model
{





    // 表名
    protected $name = 'ab';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ip_limit_text',
        'event_name_text',
        'content_type_text',
        'material_type_text'
    ];



    public function getIpLimitList()
    {
        return ['default' => __('Ip_limit default'), 'country' => __('Ip_limit country')];
    }

    public function getEventNameList()
    {
        return ['Contact' => __('Event_name contact')];
    }

    public function getContentTypeList()
    {
        return ['review' => __('Content_type review'), 'landing' => __('Content_type landing')];
    }

    public function getMaterialTypeList()
    {
        return ['1' => __('Material_type 1'), '2' => __('Material_type 2')];
    }


    public function getIpLimitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ip_limit']) ? $data['ip_limit'] : '');
        $list = $this->getIpLimitList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getEventNameTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['event_name']) ? $data['event_name'] : '');
        $list = $this->getEventNameList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getContentTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['content_type']) ? $data['content_type'] : '');
        $list = $this->getContentTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMaterialTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['material_type']) ? $data['material_type'] : '');
        $list = $this->getMaterialTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function Admin()
    {
        return $this->belongsTo('Admin', 'admin_id', 'id');
    }

    public function Landingpage()
    {
        return $this->belongsTo('Landingpage', 'landingpage_id', 'id');
    }

    public function getCountryList()
    {
        $countryModel = new CountryModel();
        $countrys = $countryModel->field('id,name')->select();

        $arr = [];
        foreach ($countrys as $key => $value) {
            $arr[$value['id']] = $value['name'];
        }

        return $arr;
    }
}
